package com.banban.user.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Component
@Slf4j
public class PushUtil {

    @Autowired
    private RestTemplateUtil restTemplateUtil;

    private final static String PUSH_URL = "https://fc-mp-a6ae93ff-b409-42db-aad6-63a0e2d9b7b9.next.bspapp.com/uni-push2";

    /**
     * 推送消息
     * @param cid
     * @param title
     * @param content
     */
    public void push(String cid, String title, String content) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("force_notification", true);
        List<String> cids = new ArrayList<>();
        cids.add(cid);
        jsonObject.put("push_clientid", cids);
        jsonObject.put("title", title);
        jsonObject.put("content", content);
        jsonObject.put("request_id", UUID.randomUUID().toString());
        log.info("push request:{}", jsonObject.toJSONString());
        JSONObject result = restTemplateUtil.postJsonDataAndReturnJson(PUSH_URL, jsonObject);
        log.info("push result:{}", result);
    }

}
